package org.example.now.service;


import org.example.now.dao.UserDao;
import org.example.now.entity.UserInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class UserService {
    @Autowired
    UserDao userDao;


    //save方法由JpaRepository接口提供
    public void addUser(UserInfoDto userInfoDto){
        userDao.save(userInfoDto);
    }

    public Page<UserInfoDto> getUserByPage(Pageable pageable){
        return userDao.findAll(pageable);
    }

    public List<UserInfoDto> getUserByUserCodeStartingWith(String userCode){
        return userDao.getUserByUserCodeStartingWith(userCode);
    }

    public List<UserInfoDto> getUserByCreateThen(Integer id){
        return userDao.getUserByIdGreaterThan(id);
    }


    public UserInfoDto getMaxIdBook(){
        return userDao.getMaxIdBook();
    }


    public List<UserInfoDto> getUserByIdAndName(String name,Integer id){
        return userDao.getUserByIdAndName( name, id);
    }

    public void updateUserName(String userCode,String userName){
         userDao.updateUserName( userCode,userName);
    }

    public void updateUserName2(String userCode,String userName){
         userDao.updateUserName2( userCode,userName);
    }

}
